package com.example.wechathook.hook;

import static de.robv.android.xposed.XposedBridge.log;
import static de.robv.android.xposed.XposedHelpers.findAndHookMethod;

import com.example.wechathook.util.PreferenceUtils;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

/**
 * 随机Hook
 * 
 * @author chencq
 *
 */
public class RandomHook extends BaseHook {

	@Override
	public void hook(XC_LoadPackage.LoadPackageParam lpp) {
		try {
			findAndHookMethod("com.tencent.mm.sdk.platformtools.bc", lpp.classLoader, "qQ", int.class,
					new XC_MethodHook() {
						@Override
						protected void afterHookedMethod(MethodHookParam param) {
							int gameType = ((Integer) param.args[0]).intValue();
							log("Random Hook,gameType:" + gameType);
							int num = 0;
							switch (gameType) {
							case 2:// 剪刀石头布
								if (PreferenceUtils.moraCheat()) {
									num = PreferenceUtils.moraNum();
									log("Random Hook,Number:" + num);
									param.setResult(num);
								}
								break;
							case 5:// 骰子
								if (PreferenceUtils.diceCheat()) {
									num = PreferenceUtils.diceNum();
									log("Random Hook,Number:" + num);
									param.setResult(num);
								}
								break;
							default:
							}
						}
					});
		} catch (Throwable e) {
			log("rand hook excepntion:" + e.getMessage());
		}
	}
}
